package com.oc.utils;

import java.util.Vector;

public class TextUtils {

		public static int findPos(String key, String[] keys){
	    	for(int i = 0; i < keys.length; i++){
	    		if( keys[i].equalsIgnoreCase(key)){
	    			return i;
	    		}
	    	}
	    	return -1;
		}
	
	   public static String findValueByKey(String key , String[] keys, String[] values){
	    	
	    	if(keys.length != values.length){
	    		return null;
	    	}
	    	
	    	int pos = 0; 
	    	for(int i = 0; i < keys.length; i++){
	    		if( keys[i].equals(key)){
	    			return values[pos]; 
	    		}
	    	}
	    	return null;
	    }
	
	
	public static String[] split(String str, String c) 
    {
        String r[] =  null;
        if(str!=null)
        {
            int lenght = str.length();
            int first = 0;            
            Vector lista = new Vector();
            if(str.indexOf(c)!=-1)
            {
                for(int i = 0; i < lenght;i++)
                {
                    if(i+c.length()<=lenght)
                    {
                        if(str.substring(i,i+c.length()).equals(c))
                        {
                            lista.addElement(str.substring(first,i));
                            first = i+c.length();
                        }
                    }
                }
                if(!str.endsWith(c))
                {
                    lista.addElement(str.substring(first,lenght));
                }
            }else
            {
                lista.addElement(str);
            }
            r= new String[lista.size()];
            for(int i=0;i<lista.size();i++)
            {
                r[i] = lista.elementAt(i).toString();
            }
        }
        return r;
    }
}
